

#include "init.h"
#include "usart.h"
#include "can.h"
#include "bsp_app.h"
#include "bsp_led.h"
#include "bsp_uart.h"

osThreadId timer_task_t;
osThreadId chassis_task_t;
osThreadId user_can_task_t;
osThreadId user_imu_task_t;
osThreadId user_dbus_task_t;




BaseType_t xTimer1Started, xTimer2Started;

osThreadId cmd_task_t;
QueueHandle_t xQueueCan = NULL;
QueueHandle_t xQueueDbus = NULL;
TimerHandle_t xAutoReloadTimer_1;
TimerHandle_t xAutoReloadTimer_2;





void task_init(void)
{
//  uint8_t app;
//  app = get_sys_cfg();
  //can send task
  osThreadDef(CHASSIS_TASK, chassis_task, osPriorityRealtime, 0, 512);
  user_can_task_t = osThreadCreate(osThread(CHASSIS_TASK), NULL);
  //pose imu task
  osThreadDef(IMU_TASK, user_imu_task, osPriorityHigh, 0, 512);
  user_imu_task_t = osThreadCreate(osThread(IMU_TASK), NULL);
  // recv joystick
  osThreadDef(DBUS_TASK, user_dbus_task, osPriorityHigh, 0, 128);
  user_dbus_task_t = osThreadCreate(osThread(DBUS_TASK), NULL);
  // bsp dbus decode protocol
  xQueueDbus = xQueueCreate(1, sizeof(joystick_t));
  // bsp can receive
  xQueueCan = xQueueCreate(24, sizeof(userCanBuf_t));
  //send chassis can data
  xAutoReloadTimer_1 = xTimerCreate("AutoReload",
                                    CHASSIS_CTL_TIMER_PERIOD,
                                    pdTRUE,
                                    0,
                                    timerChassisCtlCallback);
  xAutoReloadTimer_2 = xTimerCreate("AutoReload_2",
                                    CHAIIS_DETAL_REPORT_TIMER_PERIOD,
                                    pdTRUE,
                                    0,
                                    timerChassisReportCallback);

  if((xAutoReloadTimer_1 != NULL)&&(xAutoReloadTimer_2 != NULL))
  {
    xTimer1Started = xTimerStart(xAutoReloadTimer_1, 0);
    xTimer2Started = xTimerStart(xAutoReloadTimer_2, 0);
  }

//  osThreadDef(CMD_TASK, infantry_cmd_task, osPriorityNormal, 0, 4096);
//  cmd_task_t = osThreadCreate(osThread(CMD_TASK), NULL);
}
